package cn.elwy.rcp.demo.dialog;

import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.elwy.rcp.core.model.ui.InputModel;
import cn.elwy.rcp.ui.table.TablePane;
import cn.elwy.rcp.ui.table.TablePaneFactory;
import cn.elwy.rcp.ui.table.model.ColumnInfo;

public class TablePaneDialog extends Dialog {

  private Logger logger = LoggerFactory.getLogger(TablePaneDialog.class);
  protected Object result;
  protected Shell shell;
  private TablePane group;

  /**
   * Create the dialog.
   * @param parent
   * @param style
   */
  public TablePaneDialog(Shell parent, int style) {
    super(parent, style);
    setText("SWT Dialog");
  }

  /**
   * Open the dialog.
   * @return the result
   */
  public Object open() {
    createContents();
    shell.open();
    shell.layout();
    Display display = getParent().getDisplay();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    group.dispose();
    return result;
  }

  /**
   * Create contents of the dialog.
   */
  private void createContents() {
    shell = new Shell(getParent(), getStyle());
    shell.setSize(1200, 600);
    shell.setText(getText());
    shell.setLayout(new FillLayout(SWT.HORIZONTAL));

    SashForm sashForm = new SashForm(shell, SWT.VERTICAL);

    logger.error("cn.elwy.rcp.ui.table.setting.TablePaneConfig.demo");
    logger.info("cn.elwy.rcp.ui.table.setting.TablePaneConfig.demo");
    logger.debug("cn.elwy.rcp.ui.table.setting.TablePaneConfig.demo");
    logger.warn("cn.elwy.rcp.ui.table.setting.TablePaneConfig.demo");
    logger.trace("cn.elwy.rcp.ui.table.setting.TablePaneConfig.demo");

    group = TablePaneFactory.getTablePane(sashForm, "cn.elwy.rcp.ui.table.setting.TablePaneConfig.demo");
    List<ColumnInfo> columnInfoList = group.getTableInfo().getColumnInfoList();
    InputModel inputModel = new InputModel();
    inputModel.setInput(columnInfoList);
    group.setInputModel(inputModel);

    // group = TablePaneFactory.getTablePane(sashForm, "cn.elwy.rcp.builder.tablePane1");
    //
    group = TablePaneFactory.getTablePane(sashForm, "cn.elwy.rcp.navigation.ExplorerView.treeViwer");
    // sashForm.setWeights(new int[] { 1, 1, 1 });
    // InputModel inputModel1 = new InputModel();
    // IWorkspace workspace = ResourcesPlugin.getWorkspace();
    // inputModel1.setInput(workspace.getRoot());
    // group.setInputModel(inputModel1);
  }

}
